﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Model;
using AspNetCs.Bll;
using AspNetCs.Common;

public partial class UseCardPay : BasePage
{
    private int userId = 0;
    private int usertype = 0;
    public string cardNum = "";
    public string cardPwd = "";
    private decimal amount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        userId = StringHelper.isNumber_int(Request["userid"]);
        usertype = StringHelper.isNumber_int(Request["usertype"]);
        if (userId <= 0)
        {
            Response.Write("页面不存在!");
            Response.End();
            //ResultStr(configInfo.InstallDir+"Users/Login.aspx","请您登录!");
        }
        cardNum = Request["kahao"];
        cardPwd = Request["mima"];

        string cmdText = "select *from AddPoint where CardNum='{0}' and CardPwd='{1}' and state=0 and IsDel=0";
        cmdText = string.Format(cmdText,cardNum,cardPwd);
        DataTable dataTable = new DataTable();
        dataTable=ExcuteSqlTextBLL.GetDataTable(cmdText);

        if (dataTable.Rows.Count > 0)
        {
            amount = StringHelper.isNumber_decimal(dataTable.Rows[0]["Point"].ToString());
            int id = StringHelper.isNumber_int(dataTable.Rows[0]["id"]);
            string sqlText = "update AddPoint set UseType={0},State=1,UseId={1},UseTime='{2}' where id={3}";
            sqlText = string.Format(sqlText, usertype, this.userId, DateTime.Now, id);
            int res=ExcuteSqlTextBLL.ExcuteResult(sqlText);
        }
        else
        {
            Response.Write("用户名或密码错误或者该充值卡已经使用,请重新输入!");
            Response.End();
            //Response.Write("</script><script>alert('用户名或密码错误或者该充值卡已经使用,请重新输入');window.location.href='"+configInfo.InstallDir+"users/default.aspx';</script>");
            //Response.Write("<script>function ope(){wy_addPhotoCat('" + configInfo.InstallDir + "OnlineAddPoint.aspx','在线充值',700,520);return false;}ope();</script>");
            return;
        }
        Point_Log_Model model = new Point_Log_Model();
        model.Addtime = DateTime.Now;
        model.NetIp = StringHelper.Ip();
        model.Point = -amount;
        model.Readme = "通过充值卡充值" + -amount + "点";
        model.UserId = userId;
        model.UserType = this.usertype;
        Point_Log_Bll.CreateNew.Add(model);

        Response.Write("充值成功,充值点数:" + amount+"!");
        Response.End();
        //Response.Write("<script>alert('充值成功,充值点数:'" + amount + ");window.location.href='" + configInfo.InstallDir + "users/default.aspx';</script>");

    }
}
